#include <iostream>
using namespace std;

typedef struct Node{
    int data;
    Node* next;
} Node;

Node* head;

int isCycle(){
    Node* p1 = head;
    Node* p2 = head;
    while(p2!= NULL && p2->next!=NULL){
        p1 = p1->next;
        p2 = p2->next->next;
        if(p1==p2){
            return 1;
        }
    }
    
    return 0;
}

int main(){
    Node n1{1,NULL};
    Node n2 = {2,NULL};
    Node n3 = {3,NULL};
    Node n4 = {4,NULL};
    Node n5 = {5,NULL};
    n1.next = &n2;
    n2.next = &n3;
    n3.next = &n4;
    n4.next = &n5;
    n5.next = &n2;
    head = &n1;
    cout<<isCycle()<<endl;




    return 0;
}